package Elevator;

import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.Date;
import java.util.LinkedList;
import java.util.Observable;
import java.util.Observer;

/**
 * Created by Connor Madden.
 * User: Connor Madden
 * Date: 7/10/11
 * Time: 9:30 PM
 */
public class ElevatorTest {
    ElevatorI elevator;
    static int NUM = 0;
    static float SPEED = 1, START_LOC = 0, DESTINATION = 10;
    LinkedList<Float> positionChange;

    @BeforeMethod
    public void setUp() throws Exception {
        elevator = new Elevator(NUM, SPEED, START_LOC);
    }

    @Test
    public void testMove() throws Exception {
        elevator.addObserver(new Observer() {
            public void update(Observable o, Object arg) {
                System.out.println("Change State: " + elevator.getState());
            }
        });
        elevator.move(DESTINATION);
        float location = -1f;
        long start = new Date().getTime();
        positionChange = new LinkedList<Float>();
        while (location != DESTINATION || new Date().getTime() > start + 15000) {
            float currentLoc = elevator.getLocation();
            if (currentLoc != location) {
                positionChange.add(currentLoc);
                System.out.println("Change State: " + elevator.getState());
                location = currentLoc;
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        Assert.fail(positionChange.toString());
    }

    @Test
    public void testGetLocation() throws Exception {

    }
}
